﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyHealthByDesign.DataAccess.AccountDA;
using MyHealthByDesign.Domain;
using System.Collections.Specialized;

namespace MyHealthByDesign.Views
{
    public partial class MyHealthHistory : System.Web.UI.Page
    {
        Domain.Domain domain = new Domain.Domain();
        private const int CATEGORYHEALTHHISTORY = 3;

        protected void Page_Init(object sender, EventArgs e)
        {
            // retrieve questions for page
            List<Question> lstQuestions = domain.RetrieveQuestions(CATEGORYHEALTHHISTORY);

            // loop through questions to create display panels
            foreach (Question q in lstQuestions)
            {
                phPanels.Controls.Add(q.DisplayQuestion());
            }

            // store questions in session in order to retrieve answers on post back
            Session["Questions"] = lstQuestions;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!domain.IsUserLoggedIn())
            {
                Response.Redirect("../Default.aspx");
            }
        }

        protected void btnContinue_Click(object sender, EventArgs e)
        {
            // Go through question fields and retrieve values
            if (Session["Questions"] != null)
            {
                MasterPage ctl00 = FindControl("ctl00") as MasterPage;
                ContentPlaceHolder MainContent = ctl00.FindControl("MainContent") as ContentPlaceHolder;

                domain.SaveQuestionAnswers(MainContent); // retrieves values and save to database

                //where am I going/
                Response.Redirect("MyHealthRiskFactors.aspx");
            }
        }
    }
}